package com.unitd.base.module.logistics.service.impl;

import com.unitd.base.frame.plugins.module.service.impl.BaseServiceImpl;
import com.unitd.base.frame.plugins.mybatis.mapper.IBaseDao;
import com.unitd.base.module.logistics.po.ExpressCompany;
import com.unitd.base.module.logistics.mybatis.mapper.ExpressCompanyMapper;
import com.unitd.base.module.logistics.service.ExpressCompanyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 快递鸟接口支持快递公司编码表信息业务逻辑处理接口实现类
 *
 * @author Hudan
 * @version 1.0
 * @filename ExpressCompanyServiceImpl.java
 * @copyright www.unitd.com
 * @date 2019-01-31
 */
@Service
@Slf4j
public class ExpressCompanyServiceImpl extends BaseServiceImpl<ExpressCompany, Long> implements ExpressCompanyService {

	@Autowired
	private ExpressCompanyMapper expressCompanyMapper;

	/**
	 * @return GenericDao实现类
	 * 定义成抽象方法, 由子类实现, 完成dao的注入
	 */
	@Override
	public IBaseDao<ExpressCompany, Long> getDao() {
		return expressCompanyMapper;
	}

	/**
	 * 根据物流公司编号获取物流公司详情
	 *
	 * @param code 物流公司编号
	 * @return 物流公司详情
	 */
	@Override
	public ExpressCompany selectByCode(String code) {
		return expressCompanyMapper.selectByCode(code);
	}

	/**
	 * @param code 物流公司编号
	 * @return 物流公司名称
	 * 根据物流公司编号获取物流公司名称
	 */
	@Override
	public String selectNameByCode(String code) {
		return expressCompanyMapper.selectNameByCode(code);
	}

	@Override
	public List<ExpressCompany> selectNameByCode2(String code) {
		Example example = new Example(ExpressCompany.class);
		Example.Criteria criteria = example.createCriteria();
		criteria.andLike("code", code);
		example.setOrderByClause("name desc");

		return expressCompanyMapper.selectByExample(example);
	}
}
